﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.Xml.Linq;
using System.IO;
using System.Collections.ObjectModel;
using System.Windows.Controls.DataVisualization.Charting;
using System.Collections;
using System.Windows.Controls.DataVisualization;
using CustomControls;

using System.ComponentModel;
using ActivityTracker.Library;
using Common.Library;

namespace ActivityTracker
{
    public partial class Daily_TimespentPieChart : PhoneApplicationPage
    {
        #region Global

        bool newPageInstance = false;
        DailyChart objDailyChart = new DailyChart();

        #endregion

        #region constructor

        public Daily_TimespentPieChart()
        {
            InitializeComponent();
            newPageInstance = true;
        }

        #endregion

        #region page events

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            string SelectedDate = null;
            try
            {
                if (NavigationContext.QueryString.TryGetValue("SelectedDate", out SelectedDate) && newPageInstance)
                    chartdtp.Value = Convert.ToDateTime(SelectedDate);
                LoadChart();
                newPageInstance = false;
            }
            catch (Exception ex)
            {
                string mess = "Exception in PhoneApplicationPage_Loaded Method In Daily_TimespentPieChart file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        private void btnbarchart_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/Charts/Daily/Daily_TimespentBarChart.xaml?SelectedDate=" + chartdtp.Value, UriKind.Relative));
        }
        private void ApplicationBarMenuItem_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/Charts/Daily/Daily_CategoryBarChart.xaml", UriKind.Relative));
        }
        private void labeledPieSeries_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                this.DetailsControl.Content = ((LabeledPieSeries)sender).SelectedItem;
            }
            catch (Exception ex)
            {
                string mess = "Exception in labeledPieSeries_SelectionChanged Method In Daily_TimespentPieChart file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        #endregion

        #region  custom methods

        private void LoadChart()
        {
            try
            {
                List<ChartProp> objChartList = objDailyChart.LoadTimeSpentData(Convert.ToDateTime(chartdtp.Value), ChartType.Pie);
                if (objChartList.Count > 0)
                    txtblkResult.Visibility = Visibility.Collapsed;
                else
                    txtblkResult.Visibility = Visibility.Visible;
                ContentPanel.DataContext = objChartList;
                //mydailyChart.LegendStyle = ChartLegendStyles.hidelegend();
            }
            catch (Exception ex)
            {
                Exception exnew = new Exception("Exception in LoadChart Method In Daily_TimespentPieChart file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace);
                throw exnew;
            }
        }

        #endregion

      
    }
}